//
//  XVCRefuseReason.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/13.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XVCRefuseReason.h"
#import "XXTool.h"
#import "XMLRefuseReason.h"
#import "XVCVisitorAppointmentDetail.h"

@interface XVCRefuseReason ()

@property (nonatomic,strong) UIView *contentBackground;

@property (nonatomic,strong) UIScrollView *scrollview;

@property (nonatomic,strong) UILabel *reasonShow;

@end

@implementation XVCRefuseReason
-(UIView*)contentBackground
{
    if (_contentBackground==nil)
    {
        _contentBackground = [[UIView alloc] init];
        _contentBackground.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_contentBackground];
    }
    return _contentBackground;
}

-(UIScrollView*)scrollview
{
    if (_scrollview==nil)
    {
        _scrollview = [[UIScrollView alloc] init];
        [_contentBackground addSubview:_scrollview];
    }
    return _scrollview;
}

-(UILabel*)reasonShow
{
    if (_reasonShow==nil)
    {
        _reasonShow = [[UILabel alloc] init];
        _reasonShow.textColor = [UIColor colorWithRed:89/255.0 green:87/255.0 blue:87/255.0 alpha:1.0];
        _reasonShow.font = [XXTool systemFontOfSize:15];
        _reasonShow.numberOfLines = 0;
        [_scrollview addSubview:_reasonShow];
        
    }
    return _reasonShow;
}

-(void)initUI
{
    self.view.backgroundColor = [XXTool colorWithBackGround];
    [self.navigationItem setTitle:NSLocalizedString(@"拒绝原因", nil)];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"预约详情", nil) style:UIBarButtonItemStylePlain target:self action:@selector(clickApponintmentDetail)]];
    [self contentBackground];
    [self scrollview];
    [self reasonShow];
}

-(void)initData
{
    [self.view startLoading];
    [XMLRefuseReason requestRefuseReasonWithAppointmentID:self.appointmentID
                                               completion:^(BOOL isSuccess, XMLRefuseReason *data) {
                                                   if (isSuccess)
                                                   {
                                                       _reasonShow.text = data.value;
                                                       [self refreshLayout];
                                                   }
                                                   [self.view stopLoading];
                                               }];
}

-(void)refreshLayout:(CGRect)frame
{
    _contentBackground.frame = CGRectMake(0, 0, frame.size.width
                                              , 300);
    _scrollview.frame = CGRectMake(30, 30
                                       , frame.size.width-60
                                       , _contentBackground.frame.size.height-60);
    _reasonShow.frame = CGRectMake(0, 0, _scrollview.frame.size.width
                                       , [XXTool getTextHeightByText:_reasonShow.text
                                                                Font:_reasonShow.font
                                                               Width:_scrollview.frame.size.width]);
    _scrollview.contentSize = CGSizeMake(_scrollview.frame.size.width
                                         , _reasonShow.frame.size.height);
}

-(void)clickApponintmentDetail
{
    [XVCVisitorAppointmentDetail pushVistorAppointmentDetailWithSourceVC:self apmentID:self.appointmentID useType:XVCVisitorAppointmentDetailDelete];
}

#pragma mark api
+(void)pushRefuseReasonVCWithSourceVC:(UIViewController *)sourceVC apmentID:(NSString *)apid
{
    XVCRefuseReason *vc = [[XVCRefuseReason alloc] init];
    vc.appointmentID = apid;
    if (sourceVC)
    {
        [sourceVC.navigationController pushViewController:vc animated:YES];
    }
}

@end
